//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<ResourceLoader.h>
///	@path	~/src/scene/resource/
///	@date	2008/04/10
///	@desc	.

#pragma once

#include "xeres.h"

#include "lib/utilities/dict.h"

#include "graphics/IGeometry.h"
#include "graphics/IModel.h"
#include "graphics/IEffect.h"
#include "graphics/IEffectPool.h"

#include "gui/image/ImageResource.h"

#include "scene/resource/ResourceProvider.h"
#include "scene/resource/ILoader.h"

namespace xeres {

	/*! 
		\class	ResourceLoader
		\brief
	*/
	class ResourceLoader : public ResourceProvider , public ImageResource
	{
	protected:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		ResourceLoader( void );

		/// \dtor
		~ResourceLoader( void );

		//@}

		/*! 
			\class	Dispatcher
			\brief	Dispatcher interface for loading tasks.
		*/
		class Dispatcher
		{
		public:

			/// \name Dispatch Interface
			//@{

			virtual void InsertLoader( void ) = 0;

			//@}
		};

		/// \name Initialize & Finalize
		//@{

		/// \brief Initialize
		void Initialize( Dispatcher * dispatcher , RenderManager * renderman );

		/// \brief Finalize
		void Finalize( void );

		//@}

	public:

		/// \name Interface Method
		//@{

		/*! 
			\brief	Register geometry loader.
		*/
		bool RegisterGeometryLoader( const WString& name , RefWeak<IGeometryLoader> loader );

		/*! 
			\brief	Register model loader.
		*/
		bool RegisterModelLoader( const WString& name , RefWeak<IModelLoader> loader );

		/*! 
			\brief	Loads a geometry.
		*/
		RefPass<IGeometry> LoadGeometry( RefWeak<IData> res );

		/*! 
			\brief	Loads a model.
		*/
		RefPass<IModel> LoadModel( RefWeak<IData> res );

		/*!	
			\brief	Loads an only the fly defined effect.
		*/
		RefPass<IEffect> LoadEffectFromData( const WString& url , RefWeak<IEffectPool> pool );

		//@}

	private:

		//@ data
		Dispatcher *		m_dispatcher;

		// effect path prefix
		WString				m_effectPrefix;

		// registered loaders
		dict< WString , Ref<IGeometryLoader> >	m_geometryLoaders;
		dict< WString , Ref<IModelLoader> >		m_modelLoaders;


	};

} // namespace xeres
